﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace WindowsFormsOrderManagement
{

    //订单编号、客户、订单日期、订单详情
    //添加、删除订单详情
    public class Order 
    {

        //每个客户在一笔订单上可能买下多个商品，这就是订单明细的作用
        //不管了，先实现一个一个买的，每个用户每次只能买一件商品
        public string OrderId { get; set; }
        public Customer Customer { get; set; }
        public DateTime OrderDate { get; set; }
        public OrderDetail OrderDetails { get; set; }
        public decimal TotalAmount => OrderDetails.TotalAmount;


        //orderDetali先直接给出；

        public Order(string orderId, Customer customer, DateTime orderDate,OrderDetail orderde)
        {
            OrderId = orderId;
            Customer = customer;
            OrderDate = orderDate;
            OrderDetails = orderde;
        }

       

        public override string ToString()
        {
            string details = OrderDetails.ToString();
            return $"Order ID: {OrderId}, Date: {OrderDate:yyyy-MM-dd}\n" +
                   $"Customer: {Customer}\n" +
                   $"Order Details:\n  {details}\n" +
                   $"Total Order Amount: {TotalAmount:C}";
        }

        public override bool Equals(object obj)
        {
            if (obj == null || GetType() != obj.GetType())
                return false;

            Order other = (Order)obj;
            return OrderId == other.OrderId;
        }

        public override int GetHashCode()
        {
            return OrderId.GetHashCode();
        }
        public int CompareTo(Order other)
        {
            if (other == null) return 1;
            return OrderId.CompareTo(other.OrderId);
        }

    }
}
